package com.chang.cheng.toutiaoserver.login.controller.v1;

import com.chang.cheng.toutiaoserver.login.controller.apis.LoginControllerApi;
import com.chang.cheng.toutiaoserver.login.service.ApUserGetChannelsService;
import com.chang.cheng.toutiaoserver.login.service.ApUserGetUserService;
import com.chang.cheng.toutiaoserver.login.service.ApUserLoginService;
import com.chang.cheng.toutiaoserver.login.service.ApUserSendSmsService;
import com.chang.cheng.toutiaoserver.model.common.dtos.ResponseResult;
import com.chang.cheng.toutiaoserver.model.user.pojos.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: asus
 * @Date: 2022/01/02 17:14
 * @Description:
 */
@RestController
@RequestMapping("/app/v1_0")
public class LoginAppV1Controller implements LoginControllerApi {
    @Autowired
    private ApUserLoginService apUserLoginService;
    @Resource
    private ApUserSendSmsService apUserSendSmsService;
    @Autowired
    private ApUserGetUserService apUserGetUserService;
    @Autowired
    private ApUserGetChannelsService apUserGetChannelsService;

    @Override
    @PostMapping("/authorizations")
    //如果接收的是对象只能用@RequestBody接收json.用@RequestParam要用多个属性接收x-www-form-urlencoded
    public ResponseResult login(@RequestBody AppUser user) {
        /*form-data是上传时用的格式用MultipartFile upload,@RequestParam用不用都有见,*/
        return apUserLoginService.loginAuthAppV1(user);
    }

    // 发送验证码,这里暂放ServletContext
    @Override
    @GetMapping ("sms/codes/{mobile}")
    public ResponseResult sendSms(@PathVariable("mobile") Long mobile, HttpServletRequest request) {
        return apUserSendSmsService.sendSmsAppV1(mobile,request);
    }

    @Override
    @GetMapping ("user")
    public ResponseResult getUser() {
        return apUserGetUserService.getUserInfo();
    }

    @Override
    @GetMapping ("user/channels")
    public ResponseResult getChannels() {
        return apUserGetChannelsService.getChannels();
    }

}











